home *** CD-ROM | disk | FTP | other *** search
- comment $
-
-
-
- FOR 32 BIT PROTECDED MODE ONLY
- Writen by Adam Seychell
-
- fififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififi
- fififififififififififififififififififififi VARIOUS PROCEDURES fififififififififififififififififififififififififififi
- fififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififi
- fi fi
- fi THIS FILE CONTAINS USEFUL PROCEDURES fi
- fi fi
- fi THEY SHOULDN'T NEED TO BE CHANGED TO MUSH fi
- fi fi
- fififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififi
-
-
-
-
-
- fififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififi
- fififififififififififififififififififififi VARIOUS PROCEDURES fififififififififififififififififififififififififififi
- fififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififi
- ’ÕÕÕÕÕÕÕÕÕÕÕÕÕ—ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ≥ proc Name ≥ Discription
- ΔÕÕÕÕÕÕÕÕÕÕÕÕÕÿÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ≥ ClrScr ≥ fills video memory (B8000h-B8FFFh) with AX
- ≥ ≥
- √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- ≥PRINT_CHAR ≥ prints a character AL with color AH at the cursor
- ≥ ≥ AH = attribute byte ( COLOR )
- ≥ ≥
- √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- ≥ TEXT ≥ Prints a string at the cursor position.
- ≥ ≥ expects : EDX = offset of string in data segment
- ≥ ≥ AH = attribute byte ( COLOR )
- ≥ ≥
- √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- ≥HEX_DWORD ≥ Prints the value of EDX, DX or DL as hexidecimal
- ≥HEX_WORD ≥ at the cursor position.
- ≥HEX_BYTE ≥ expects : EDX = value to display
- ≥ ≥ AH = attribute byte ( COLOR )
- ≥ ≥
- √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- ≥BINARY_DWORD ≥ Same as hex above except it prints in binary
- ≥BINARY_WORD ≥
- ≥BINARY_BYTE ≥
- √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- ≥DEC_DWORD ≥ Same as hex above except it prints in decimal
- ≥DEC_WORD ≥
- ≥DEC_BYTE ≥
- √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- ≥SCROLL_SCREEN≥Scrolls the screen up a line.
- ≥ ≥
- √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- ≥SET_TIMER ≥Sets the timer 0 register of the 8242 PIC
- ≥ ≥ to the value in AX
- √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- ≥RANDOM ≥returns EAX = a random number CL bits in size
- ≥ ≥
- √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- ≥SQRT ≥Returns EAX with the square root of EAX.
- ≥ ≥
- ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒ¡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
-
-
-
-
-
-
-
-
- $
-
- DATA32 SEGMENT PUBLIC 'DATA' USE32
-
- ; Various varibles used by the procedures
- random_init dd 1010111000110111101010011011b
- clicker db 0
- HexChar db '0123456789ABCDEF'
-
- ; Contains the current cursor cordinates used by the printing procs
- Cursor_X db 0,0; Contain the current cursor cordinates
- Cursor_Y db 0,0; used by the printing procs ( see file PROCS.INC )
- DATA32 ENDS
-
-
-
-
-
- public Click
- public ClrScr
- public Scroll_Screen
- public Set_timer
- public TEXT
- public binary_Dword
- public binary_Word
- public binary_Byte
- public Hex_Dword
- public Hex_Word
- public Hex_Byte
- public DEC_Dword
- public DEC_Word
- public DEC_Byte
- public PRINT_CHAR
- public SQRT
- public Random
-
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ Click speaker ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- Click proc near
- xor clicker,010b
- mov al,clicker
- out 61h,al
- ret
- click endp
-
- ; ÕÕÕÕÕÕÕÕÕÕÕÕÕÕ CLEAR THE SCREEN ( FILL WITH ATTRIBUTES AH ) ÕÕÕÕÕÕÕÕÕÕÕÕ
- ClrScr proc near
- PUSH edi ecx eax es
- push fs
- pop es
- mov edi,0b8000h
- cld
- xor al,al
- mov ecx,2000
- rep stosw
- POP es eax ecx edi
- ret
- ClrScr endp
-
-
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ SCROLL THE SCREEN UP A LINE ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- Scroll_Screen proc near
- PUSH esi edi ecx eax es
- push fs
- pop es
- mov edi,0b8000h
- mov esi,0B8000h+0a0h
- cld
- mov ecx,1000-40
- rep movs dword ptr es:[edi],es:[esi]
- ; now screen is scrolled up, must clear bottom line
- mov ecx,80
- cxtln: mov byte ptr es:[0b8000h+(80*24*2)-2+ecx*2],0
- loop cxtln
- POP es eax ecx edi esi
- ret
- Scroll_Screen endp
-
-
- Set_timer proc near
- ;ÕÕÕÕÕÕÕ SET THE PIT (8253) TIMER NUMBER 0 TO THE VALUE IN AX REGISTER ÕÕÕÕÕ
- shl eax,8
- mov al,00110100b
- out 43h,al
- shr eax,8
- out 40h,al
- mov al,ah
- out 40h,al
- ret
- Set_timer endp
-
-
-
-
-
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕPRINT TEXTÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ; PRINTS A STRING ON SCREEN ( TEXT MODE 3 )
- ; Expects edx > offset of string in the data segment
- ; Cursor_X,Cursor_Y > position (X,Y) on the screen
- ; ah > attribute byte ( colors )
- ;NOTE: string ends with a '$'
- ; Cursor_X is returned with the X position at the end of the string
- TEXT proc near
- push eax edx
- textlop: mov al,[edx]
- inc edx
- cmp al,'$'
- jz exit_text
- call print_char
- jmp textlop
- exit_text: pop edx eax
- ret
- TEXT ENDP
-
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ PRINT BINARY NUMBER OF THE REGISTER EDXÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ; Similar to the TEXT proc near above
- ; Expects :
- ; ah = color
- ; Cursor_X,Cursor_Y position (X,Y) on the screen
- ;
- binary_Dword proc near ; prints EDX
- push ecx
- mov ecx,32
- jmp binSizeSet
- binary_Word proc near ; prints DX
- push ecx
- mov ecx,16
- rol edx,16
- jmp binSizeSet
- binary_Byte proc near ; prints DL
- push ecx
- mov ecx,8
- rol edx,24
- BinSizeSet: push eax
- binary_digit:
- mov al,'0'
- rol edx,1
- jnc bin_p_0
- mov al,'1'
- bin_p_0: call print_char ;prints a char al : color = ah
- loop binary_digit
- pop eax ecx
- ret
- Binary_Byte endp
- Binary_Word endp
- Binary_DWord endp
-
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕPRINT HEXIDECIMAL NUMBER OF THE REGISTER EDXÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ; Expects :
- ; ah = color
- ; Cursor_X,Cursor_Y position (X,Y) on the screen
- ;
- Hex_Dword proc near ; prints EDX
- push ecx
- mov ecx,8
- jmp strt_hex
- Hex_Word proc near ; prints DX
- push ecx
- mov ecx,4
- rol edx,16
- jmp strt_hex
- Hex_Byte proc near ; prints DL
- push ecx
- rol edx,24
- mov ecx,2
- strt_hex:
- push esi
- HexPrnt: rol edx,4
- mov esi,edx
- and esi,0fh
- mov al,HexChar+esi
- call print_char
- Loop HexPrnt
- pop esi ecx
- ret
- endp
- endp
- endp
-
-
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ PRINT DECIMAL NUMBER OF THE REGISTER EDX ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ; Expects :
- ; ah = color
- ; Cursor_X,Cursor_Y position (X,Y) on the screen
- ;
-
- DEC_Dword proc near ; prints EDX
- push ecx esi edx
- mov ESI,9*4
- jmp strt_dec
- DEC_Word proc near ; prints DX
- push ecx esi edx
- mov ESI,4*4
- and edx,0FFFFh
- jmp strt_dec
- DEC_Byte proc near ; prints DL
- push ecx esi edx
- mov ESI,2*4
- and edx,0FFh
-
- DATA32 SEGMENT PUBLIC 'DATA' use32
- dec_diver dd 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000
- DecVal23 dd 0
- tmpdec_color07 db 0
- ENDS
-
- strt_dec:
- push EAX
- mov tmpdec_color07,ah ; save color
- mov decVal23,EDX
- dec83: mov ECX, Dec_diver + ESI
-
- mov eax,decVal23
- xor edx,edx
- div ECX
- mov DecVal23,EDX ; use remainder
- ; use quot as digit number
- add al,'0' ; print digit
- mov ah,tmpdec_color07
- call print_char
- sub ESI,4
- jge dec83
-
- pop EAX EDX ESI ECX
- ret
- endp
- endp
- endp
-
-
-
-
-
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ PRINT A CHARACTER ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ; EXPECTS:
- ; al character to print
- ; ah attribute byte
- ; Cursor_X,Cursor_Y position (X,Y) on the screen
- PRINT_CHAR proc near
- ;-- line feed ----------------------------------
- cmp al,0Ah
- jnz no_feed
- inc Cursor_Y ; move curser down a line
- jmp char_printed
- no_feed: ;-- carage return ------------------------------------
- cmp al,0Dh
- jnz no_carg
- mov Cursor_X,0 ; return curser to start
- jmp char_printed
- no_carg: ;-- print the character on the screen -----------------
- push eax ecx
- mov ecx,eax
- xor eax,eax
- mov eax,80
- mul Cursor_Y
- add ax,word ptr Cursor_X
- mov fs:[0b8000h+2*eax],CX
- inc Cursor_X
- pop ecx eax
-
- ; ----- don't let the curser go off the screen -----------
- char_printed: cmp Cursor_X,80
- jb k23
- mov Cursor_X,0
- inc Cursor_Y
- k23: cmp Cursor_Y,25
- jb k24
- call Scroll_Screen
- mov Cursor_Y,24
- k24: ret
- endp
-
-
-
-
-
- SQRT proc near
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ; returns EAX with the SQUARE ROOT of EAX.
- ;
- ; Uses newtons method: Xn+1 = Xn - f(Xn) / f'(Xn)
- ; f'(x) is the derivitive of f(x)
- ;
- ; For square routes: f(x) = x*x - ( Root value i.e EAX)
- ; and f'(x) = 2x
- ;
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ;
- mov edi,eax
- ;----- Get Estimated Root Value ( ebp = rough value of the sqrt of EAX ) ---
- bsr ecx,edi ; Get bit number of highest NZ bit
- shr cl,1 ; Half this highest bit number
- mov ebp,edi ; Rotate Root Value by
- shr ebp,cl ; the bit number to get a estimate root.
-
-
- ;----- Main Loop that makes EBP converge to the square root of EDI ------
- calc_sqrt_Loop:
- push EBP ; save x so can check if x has converged
- mov EBX,EBP
- shl EBX,1 ; ebx = f'(x) = 2x
-
- mov EAX,EBP
- mul EBP
- sub EAX,EDI ; eax = f(x) = X*X - Root_value
- sbb EDX,0 ; use 64bit subtract
-
- div EBX ; eax = f(Xn) / f'(Xn)
-
- sub EBP,EAX ; ebp = Xn+1 = Xn - f(Xn) / f'(Xn)
- pop EAX ; look at old value
- cmp EBP,EAX ; loop only if new value is different
- jnz calc_sqrt_Loop
- ;-------------------------- End of Loop --------------------------------
-
- mov eax,ebp ; EBP contians the square root of EDI
- ret
- ;ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- endp
-
-
-
- Random proc near
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- ; EAX = a random number CL bits in size
- ;
- ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
- xor eax,eax
- mov bl,byte ptr random_init
- and bl,1
-
- Gen_bit: ; make n bit numbers
- shl eax,1
-
- mov edx,random_init
-
- shr edx,9
- xor bl,dl
-
- shr edx,5
- xor bl,dl
-
- bt ebx,1
- rcr random_init,1
- setc bl
- or al,bl
-
- dec cl
- jnz Gen_bit
- ret
- ;ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
- endp
-